package com.xuanwu.ai.flow.controller;

import com.xuanwu.ai.core.domain.ErrorData;
import com.xuanwu.ai.flow.dto.LoginRespDTO;
import com.xuanwu.ai.flow.model.TenantFlowAccount;
import com.xuanwu.ai.flow.service.AuthServiceImpl;
import com.xuanwu.ai.web.views.ResponseVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "鉴权相关接口", produces = "application/json")
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private AuthServiceImpl authService;

    @PostMapping("/login")
    public ResponseVo<LoginRespDTO> login(@RequestBody TenantFlowAccount tenantFlowAccount){
        if (StringUtils.isEmpty(tenantFlowAccount.getFlowAccount())) {
            return ResponseVo.fail("401", new ErrorData(401, "租户流程账号不能为空"));
        }
        if (StringUtils.isEmpty(tenantFlowAccount.getFlowAccessKey())) {
            return ResponseVo.fail("401", new ErrorData(401, "accessKey不能为空"));
        }
        LoginRespDTO loginRespDTO = authService.login(tenantFlowAccount);
        return ResponseVo.success(loginRespDTO);
    }
}
